<template>
	<view class="contents" style="height: 100vh;">
			<view class="formss">
				<u--form :model="form" :rules="rules" ref="uForm">
					<u-form-item  prop="password">
						<u-input size="large" color="#ffffff" v-model="form.oldPassword" placeholder="请输入原密码"  disableDefaultPadding prefixIcon="lock" style="background: rgba(255,255,255,.3);" shape="circle"/>
					</u-form-item>
					<u-form-item  prop="newPassword">
						<u-input size="large" color="#ffffff" v-model="form.newPassword" placeholder="请确认新密码"  disableDefaultPadding prefixIcon="lock" style="background: rgba(255,255,255,.3);" shape="circle"/>
					</u-form-item>
				</u--form>
				<u-button shape="circle" size="large" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))" style="margin-top: 100upx;"  @click="pays">确 定</u-button>
				<!-- <u-button shape="circle" size="large" color="linear-gradient(to right, rgb(0, 0, 0), rgb(0, 0, 0))" style="margin-top: 40upx;"  @click="pays">确定</u-button> -->
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			const equalToPassword = (rule, value, callback) => {
			      if (this.form.password !== value) {
			        callback(new Error('两次输入的密码不一致'))
			      } else {
			        callback()
			      }
			    }
			return {
				form: {
					oldPassword: '',
					newPassword:'',
				},
				rules: {
					oldPassword: [{ required: true, message: '请输入新密码!', trigger: ['blur', 'change'] }],
					newPassword: [
						{ required: true, message: '请输入确认密码!', trigger: ['blur', 'change'] }
					]
				}
			};
		},
		methods:{
			pays(){
				this.$refs.uForm.validate().then(res => {
					this.https('/system/user/profile/updatePwd?oldPassword='+this.form.oldPassword+'&newPassword='+this.form.newPassword,{},{
						Authorization: 'Bearer '+uni.getStorageSync('token')
					},'put').then(res=>{
						console.log(res)
						if(res.code == 200){
								uni.showToast({
									title:'修改成功，正在退出登录',
									icon:'none'
								}),
								setTimeout(()=>{
									uni.clearStorageSync();
									uni.reLaunch({
										url:'/pages/login/login'
									})
								},2000)
						}
					})
				}).catch(errors => {
					console.log(2)
				})
			},
		}
	}
</script>

<style lang="scss">

</style>
